#include <bits/stdc++.h>

using namespace std;


class Solution {
public:
    int findNthDigit(int n) {
        if(n<10)return n;
        long long num=1,tmp=1;//标记是当前遍历的位数
        while(true){
            tmp=0.9*pow(10,num)*num;
            if(n-tmp<0){
                break;
            }
            n-=tmp;
            num++;
        }
        long long  base=pow(10,num-1)+((n-1)/num);
       // cout << base << " "<< num<< " "<< n<<endl;    
        tmp=(n-1)%num; //0,1
        //cout << tmp <<endl;
        return to_string(base)[tmp]-'0';
    }
};

int main(){
    freopen("in.txt","r",stdin);
    Solution s;
    int n;
    while(cin >>n)
        cout << s.findNthDigit(n)<<endl;



    return 0;
}